package exammanager;

import java.awt.BorderLayout;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import questionmanager.GUIQuestionTypeDisplay;
import structure.QuestionType;


public class GuiQuestionAddLeft extends JPanel{
	
	private static final long serialVersionUID = 1L;
	private GUIQuestionAdd parent;
	private GUIQuestionTypeDisplay display;
	
	public GuiQuestionAddLeft(GUIQuestionAdd parent) {
		this.parent = parent;
		setLayout(new BorderLayout());
		setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
		display = new GUIQuestionTypeDisplay();
		
		display.getJList().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		display.getJList().addListSelectionListener(new QuestionTypeSelectionListener());
		display.getJList().addMouseListener(new QuestionTypeMouseListener());
		add(display,BorderLayout.CENTER);
		display.getQuestionTypeFromDB();
	}
	
	class QuestionTypeMouseListener extends MouseAdapter{

		@Override
		public void mouseClicked(MouseEvent e) {
			switch(e.getModifiers()) {
				case InputEvent.BUTTON1_MASK: {  
					super.mouseClicked(e);	
					break;
		        }
				case InputEvent.BUTTON2_MASK: {    
					break;
		        }
				case InputEvent.BUTTON3_MASK: {
			        break;
		        }
			}
		}
	}
	
	class QuestionTypeSelectionListener implements ListSelectionListener{
		
		@Override
		public void valueChanged(ListSelectionEvent e) {
			if(!e.getValueIsAdjusting()){
				QuestionType qt = display.getJList().getSelectedValue();
				parent.getRightPanel().refresh(new int[] {qt.gettID()});
			}
		}
	}
}
